//
//  ShaiWuCell.m
//  MyTest
//
//  Created by zhiyou on 16-4-14.
//  Copyright (c) 2016年 wangyang. All rights reserved.
//

#import "ShaiWuCell.h"

@implementation ShaiWuCell
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _bgImgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_bgImgView];
        
        [_bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.offset(0);
            make.height.equalTo(self.mas_height).multipliedBy(.7);
        }];
        
        _smallImgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_smallImgView];
        
        [_smallImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
            make.bottom.equalTo(_bgImgView.mas_bottom).offset(-5);
            make.width.height.equalTo(self.mas_width).multipliedBy(.2);
        }];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _timeLabel.font = [UIFont systemFontOfSize:10];
        _timeLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_smallImgView.mas_right).offset(5);
            make.bottom.equalTo(_bgImgView.mas_bottom).offset(-5);
            make.height.equalTo(_smallImgView.mas_height).multipliedBy(.5);
            make.right.offset(0);
        }];
        
        
        _sourceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _sourceLabel.font = [UIFont systemFontOfSize:12];
        _sourceLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_sourceLabel];
        
        [_sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_smallImgView.mas_right).offset(5);
            make.right.offset(0);
            make.bottom.equalTo(_timeLabel.mas_top).offset(0);
            make.height.equalTo(_timeLabel.mas_height);
        }];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.top.equalTo(_bgImgView.mas_bottom).offset(0);
            make.height.equalTo(self.mas_height).multipliedBy(.15);
        }];
        
        _supportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _supportBtn.frame = CGRectZero;
        [self.contentView addSubview:_supportBtn];
        
        [_supportBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(0);
            make.top.equalTo(_titleLabel.mas_bottom).offset(0);
            make.height.equalTo(_titleLabel.mas_height);
            make.width.equalTo(self.mas_width).multipliedBy(.3);
        }];
        
        _agaistBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _agaistBtn.frame = CGRectZero;
        [self.contentView addSubview:_agaistBtn];
        
        [_agaistBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_supportBtn.mas_right).offset(2);
            make.top.equalTo(_titleLabel.mas_bottom).offset(0);
            make.height.equalTo(_titleLabel.mas_height);
            make.width.equalTo(self.mas_width).multipliedBy(.3);
        }];
        
        _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _commentBtn.frame = CGRectZero;
        [self.contentView addSubview:_commentBtn];
        
        [_commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_agaistBtn.mas_right).offset(2);
            make.top.equalTo(_titleLabel.mas_bottom).offset(0);
            make.height.equalTo(_titleLabel.mas_height);
            make.width.equalTo(self.mas_width).multipliedBy(.3);
        }];
    }
    return self;
}

- (void)setShaiWu:(ShaiWu *)shaiWu
{
    _shaiWu = shaiWu;
    
    [_bgImgView sd_setImageWithURL:[NSURL URLWithString:_shaiWu.front_pic]];
    [_smallImgView sd_setImageWithURL:[NSURL URLWithString:_shaiWu.author_avatar]];
    _sourceLabel.text = _shaiWu.name;
    _timeLabel.text = _shaiWu.publish_time;
    _titleLabel.text = _shaiWu.title;
    [_supportBtn setTitle:[NSString stringWithFormat:@"赞 %@",_shaiWu.support] forState:UIControlStateNormal];
    [_agaistBtn setTitle:[NSString stringWithFormat:@"差 %@",_shaiWu.agaist] forState:UIControlStateNormal];
    [_commentBtn setTitle:[NSString stringWithFormat:@"评论 %@",_shaiWu.comment_count] forState:UIControlStateNormal];
    
    _supportBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    _agaistBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    _commentBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    [_supportBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_agaistBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_commentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
}








@end
